import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";
import type { ResultType } from "@/utils/http/types";

type ResultPage = ResultType & {
  data: {
    data: Array<object>;
    total: number;
    current_page: number;
    per_page: number;
  };
};

/** 获取系统管理-角色管理列表 */
export const getRoleList = (data?: object) => {
  return http.request<ResultPage>("post", baseUrlApi("/role/get_list"), {
    data
  });
};

/** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单 */
export const getRoleMenuIds = (data?: object) => {
  return http.request<ResultType>(
    "get",
    baseUrlApi("/role/get_role_menu_ids"),
    {
      params: data
    }
  );
};

/** 获取用户所有角色 */
export const getUserRoleList = (params?: object) => {
  return http.request<ResultType>("get", baseUrlApi("/role/get_user_roles"), {
    params
  });
};

export const setRoleData = (data?: object) => {
  return http.request<ResultType>("post", baseUrlApi("/role/save_data"), {
    data
  });
};

export const delRoleData = (id: number) => {
  return http.request<ResultType>("delete", baseUrlApi("/role/del_data"), {
    params: { id }
  });
};

/** 更新角色对应控制权限 */
export const setRoleAllowAuth = (data?: object) => {
  return http.request<ResultType>(
    "post",
    baseUrlApi("/role/set_role_allow_auth"),
    {
      data
    }
  );
};

/** 更新角色状态 */
export const setRoleStatus = (data?: object) => {
  return http.request<ResultType>("post", baseUrlApi("/role/set_role_status"), {
    data
  });
};
